package com.atguigu.lease.web.admin.service.Impl;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.web.admin.mapper.*;
import com.atguigu.lease.web.admin.service.ApartmentService;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.atguigu.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.atguigu.lease.web.admin.vo.agreement.AgreementVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: 李壮
 * @CreateTime: 2025-05-13
 * @Version: 1.0
 */

@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement> implements LeaseAgreementService {


    @Resource
    LeaseAgreementMapper leaseAgreementMapper;

    @Resource
    ApartmentMapper apartmentMapper;

    @Resource
    RoomInfoMapper roomInfoMapper;

    @Resource
    PaymentTypeMapper paymentTypeMapper;

    @Resource
    LeaseTermMapper leaseTermMapper;


    @Override
    public AgreementVo getAgreementById(Long id) {

        AgreementVo agreementVo = new AgreementVo();
        LeaseAgreement leaseAgreement = leaseAgreementMapper.selectById(id);

        if (leaseAgreement != null){
            BeanUtils.copyProperties(leaseAgreement,agreementVo);

            agreementVo.setApartmentInfo(apartmentMapper.selectById(leaseAgreement.getApartmentId()));

            agreementVo.setRoomInfo(roomInfoMapper.selectById(leaseAgreement.getRoomId()));

            agreementVo.setPaymentType(paymentTypeMapper.selectById(leaseAgreement.getPaymentTypeId()));

            agreementVo.setLeaseTerm(leaseTermMapper.selectById(leaseAgreement.getLeaseTermId()));
        }

        return agreementVo;
    }

    @Override
    public IPage<AgreementVo> pageLeaseAgreementByQuery(IPage<AgreementVo> page, AgreementQueryVo agreementQueryVo) {

        return leaseAgreementMapper.pageLeaseAgreementByQuery(page,agreementQueryVo);

    }
}
